package main.test.SparkAPI.GraphXApi
import org.apache.spark._
import org.apache.spark.graphx._
// To make some of the examples work we will also need RDD
import org.apache.spark.rdd.RDD

class VertexProperty()
case class UserProperty(val name: String) extends VertexProperty
case class ProductProperty(val name: String, val price: Double) extends VertexProperty

object GetStarted {
  // The graph might then have the type:
  var graph: Graph[VertexProperty, String] = null
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
    sparkConf.setAppName("createGraph").setMaster("local[*]")
    val sc = new SparkContext(sparkConf)


    // Create an RDD for the vertices
    val users: RDD[(VertexId, (String, String))] =
      sc.parallelize(Array((3L, ("rxin", "student")), (7L, ("jgonzal", "postdoc")),
        (5L, ("franklin", "prof")), (2L, ("istoica", "prof"))))
    // Create an RDD for edges
    val relationships: RDD[Edge[String]] =
      sc.parallelize(Array(Edge(3L, 7L, "collab"),    Edge(5L, 3L, "advisor"),
        Edge(2L, 5L, "colleague"), Edge(5L, 7L, "pi")))
    // Define a default user in case there are relationship with missing user
    val defaultUser = ("John Doe", "Missing")
    // Build the initial Graph
    val graph: Graph[(String, String), String] = Graph(users, relationships, defaultUser)
    // Count all users which are postdocs
    val postDocCNT1 = graph.vertices.filter { case (id, (name, pos)) => pos == "postdoc" } .count
    val postDocCNT2 = graph.vertices.filter(x => x._2._2 == "postdoc").count


    // Count all the edges where src > dst
    val srcBdst = graph.edges.filter(e => e.srcId > e.dstId).count
    println(postDocCNT1,postDocCNT2,srcBdst)



  }

}
